/**
 * 
 */
package qy.jalgotrade.utils.resamplebase;

import java.time.ZonedDateTime;

/**
 * @author qy
 *
 */
public class MonthRange extends TimeRange {

	private ZonedDateTime __begin;

	private ZonedDateTime __end;

	/**
	 * 
	 * @param dateTime
	 */
	public MonthRange(ZonedDateTime dateTime) {

		super();
		__begin = ZonedDateTime.of(dateTime.toLocalDate().withDayOfMonth(1), DAY_TRADE_BEGIN_TIME, dateTime.getZone());

		// Calculate the ending date.
		if (dateTime.getMonthValue() == 12) {
			__end = ZonedDateTime.of(dateTime.getYear() + 1, 1, 1, __begin.getHour(), __begin.getMinute(),
			        __begin.getSecond(), __begin.getNano(), __begin.getZone());
		} else {
			__end = ZonedDateTime.of(dateTime.getYear(), dateTime.getMonthValue() + 1, 1, __begin.getHour(),
			        __begin.getMinute(), __begin.getSecond(), __begin.getNano(), __begin.getZone());
		}
	}

	/*
	 * (non-Javadoc)
	 * @see qy.jalgotrade.utils.resamplebase.TimeRange#belongs(java.time.ZonedDateTime)
	 */
	@Override
	public boolean belongs(ZonedDateTime dateTime) {

		return (dateTime.isEqual(__begin) || dateTime.isAfter(__begin)) && dateTime.isBefore(__end);
	}

	/*
	 * (non-Javadoc)
	 * @see qy.jalgotrade.utils.resamplebase.TimeRange#getBeginning()
	 */
	@Override
	public ZonedDateTime getBeginning() {

		return __begin;
	}

	/*
	 * (non-Javadoc)
	 * @see qy.jalgotrade.utils.resamplebase.TimeRange#getEnding()
	 */
	@Override
	public ZonedDateTime getEnding() {

		return __end;
	}
}
